package com.xingkong.app;

import java.io.InputStream;
import java.net.URL;

import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;
import org.apache.hadoop.io.IOUtils;
/**
 * 使用URLStreamHandlerFactory读取HDFS文件
 * run as argument:hdfs://192.168.99.101:8020/user/input/README.txt
 */
public class URLCat {
	static {
		URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
	}
	public static void main(String[] args) throws Exception{
		InputStream in=null;
		try{
			in=new URL(args[0]).openStream();
			IOUtils.copyBytes(in, System.out, 4096,false);
		}finally{
			IOUtils.closeStream(in);
		}
	}
}
